/**
 * @file       NetworkModeSettingsPanel.cpp
 * @brief      TODO
 * @author     Huabo Zheng
 * @date       Feb 3, 2012
 * @Copyright  2012, www.netgear.com Inc. All rights reserved.
 */

#include "NetworkModeSettingsPanel.h"
#include "Panel.h"
#include "MenuButton.h"
#include "IEventListener.h"
#include "KeyboardListener.h"
#include "typedefine.h"
#include "ConfimBox.h"
using namespace NS_LCD_AFW;

TMenuItems CNetworkModeSettingsPanel::g_sMenuItem[] =
{
		{ "ChangeToNatItem", "1. Change to NAT mode", CRect(1, 1, LCD_WIDTH, 1),(AFW_EventCallBack)(&CNetworkModeSettingsPanel::onChangeToNatMode) },
		{ "ChangeToRouterItem", "2. Change To Router mode", CRect(1, 2,LCD_WIDTH, 1), (AFW_EventCallBack)(&CNetworkModeSettingsPanel::onChangeToRouterMode) },
		{ "ChangeToTransparentItem", "3. Change To Transparent mode", CRect(1,3, LCD_WIDTH, 1), (AFW_EventCallBack)(&CNetworkModeSettingsPanel::onChangeToTransparentMode) }
};

CNetworkModeSettingsPanel::CNetworkModeSettingsPanel()
{
}

CNetworkModeSettingsPanel::~CNetworkModeSettingsPanel()
{
}

int CNetworkModeSettingsPanel::onCreate()
{
	int iRet = ERR_SUCCESS;
	CMenuButton *pMenuItem = NULL;
	IEventListener *pListener = NULL;

	for (int i = 0; i < sizeof(g_sMenuItem) / sizeof(g_sMenuItem[0]); ++i)
	{
		OBJ_NEW(CMenuButton, pMenuItem);
		if (NULL == pMenuItem || ERR_SUCCESS != (iRet = pMenuItem->create(
				g_sMenuItem[i].pszItemName, g_sMenuItem[i].rect, this)))
		{
			goto err_proc;
		}
		pListener = new CKeyboardListener(this,
				ENTER_KEY_PRESSED_EVENT_ID, g_sMenuItem[i].pCallBack, true);
		if (NULL == pListener || ERR_SUCCESS != (iRet
				= pMenuItem->addEventListener(pListener)))
		{
			goto err_proc;
		}
		pMenuItem->setText(g_sMenuItem[i].pszDisplayName);
		if (ERR_SUCCESS != (iRet = this->add(pMenuItem)))
		{
			goto err_proc;
		}
	}
	return CPanel::onCreate();

	err_proc: if (NULL != pListener)
	{
		pListener->destory();
		pListener = NULL;
	}
	if (NULL != pMenuItem)
	{
		pMenuItem->destory();
		pMenuItem = NULL;
	}
	return iRet;
}

int CNetworkModeSettingsPanel::onEnterKeyPress()
{
	//Change to the sub menu or configuration items screen of  the selected item
	return CPanel::onEnterKeyPress();
}

int CNetworkModeSettingsPanel::onEscKeyPress()
{
	// Return To Main Menu Screen
	return CPanel::onEscKeyPress();
}

int CNetworkModeSettingsPanel::onUpKeyPress()
{
	//Switch to prev Menu Item
	return CPanel::onUpKeyPress();
}

int CNetworkModeSettingsPanel::onDownKeyPress()
{
	// Switch to next Menu Item
	return CPanel::onDownKeyPress();
}

void CNetworkModeSettingsPanel::onChangeToNatMode(int id, int param)
{
	// TODO: if getCurMode ==  NAT then return;else
	CConfimBox dlgBox(this);
	if (ID_OK
			== dlgBox.doModal(
					"Notice:danger,what do you want to do?onChangeToNatMode,Are you sure?"))
	{
		//TODO: invoke change to nat api here

	}
	else
	{
		//do nothing;
	}
}

void CNetworkModeSettingsPanel::onChangeToRouterMode(int id, int param)
{
	// TODO: if getCurMode ==  ROUTEE then return;else
	CConfimBox dlgBox(this);
	if (ID_OK
			== dlgBox.doModal(
					"Notice:danger,what do you want to do?onChangeToRouterMode,Are you sure?"))
	{
		//TODO: invoke change to nat api here

	}
	else
	{
		//do nothing;
	}
}

void CNetworkModeSettingsPanel::onChangeToTransparentMode(int id, int param)
{
	// TODO: if getCurMode ==  Transparent then return;else
	CConfimBox dlgBox(this);
	if (ID_OK
			== dlgBox.doModal(
					"Notice:danger,what do you want to do?onChangeToTransparentMode,Are you sure?"))
	{
		//TODO: invoke change to nat api here

	}
	else
	{
		//do nothing;
	}
}

